home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks '96 / MenuMadness / Source / C Source / MenuUtils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-21  |  1.8 KB  |  102 lines  |  [TEXT/CWIE]

  1. #include "MenuUtils.h"
  2.  
  3. OSErr    SetMenuItemTextByState(MenuHandle menu, short item, Boolean state, short strListID)
  4. {
  5.     Str255    str;
  6.  
  7.     GetIndString(str, strListID, state ? 2 : 1);
  8.     SetItem(menu,item,str);
  9.     
  10.     return noErr;
  11. }
  12.  
  13. OSErr    SetMenuProcPointer(short    menuID, long procPointer)
  14. {
  15.     Handle    h = GetResource('MDrw', menuID);
  16.     
  17.     if (!h)
  18.         return resNotFound;
  19.         
  20.     * (long *) *h = procPointer;
  21.     
  22.     return noErr;
  23. }
  24.  
  25. void TickThisItem (short    targetItem, MenuHandle    menu)
  26. {
  27.     short    itemCount, x;
  28.  
  29.     itemCount = CountMItems(menu);
  30.     for (x = 1 ; x <= itemCount ; x++)
  31.         CheckItem(menu,x, x == targetItem);
  32. }
  33.  
  34.  
  35. Boolean GetItemEnabled(MenuHandle menu, short item)
  36. {
  37.     long    flags = menu[0]->enableFlags;
  38.     
  39.     if (!(flags & 1L))
  40.         return false; // whole menu is disabled
  41.         
  42.     if ((item <= 31)  && ((flags & (1L << item)) == 0))
  43.         return false;
  44.         
  45.     return true;
  46. }
  47.  
  48. void SetItemEnabled(MenuHandle menu, short item, Boolean enabled)
  49. {
  50.     if (enabled)
  51.         EnableItem(menu,item);
  52.     else
  53.         DisableItem(menu,item);
  54. }
  55.  
  56. void DisableAllMenuItems (MenuHandle    menu)
  57. {
  58.     short    itemCount, x;
  59.  
  60.     itemCount = CountMItems(menu);
  61.     for (x = 1 ; x <= itemCount ; x++)
  62.         DisableItem(menu,x);
  63. }
  64.  
  65. Boolean ItemIsDivider(MenuHandle menu, short item);
  66. Boolean ItemIsDivider(MenuHandle menu, short item)
  67. {
  68.     Str255    str;
  69.     
  70.     GetItem(menu, item, str);
  71.     return ((str[0] == 1) && (str[1] == '-'));
  72. }
  73.  
  74.  
  75. OSErr    ShowMenuBalloon(MenuHandle    theMenu, short previousItem, short inItem, Rect    *itemRect)
  76. {
  77.     if (!HMGetBalloons() || (inItem== previousItem))
  78.         return noErr;
  79.         
  80.     if (inItem )
  81.         {
  82.         Point    tip;
  83.         
  84.         if (ItemIsDivider(theMenu, inItem))
  85.             inItem = -1;
  86.         
  87.         tip.h = itemRect->right;
  88.         tip.v = (itemRect->top + itemRect->bottom) >>1;
  89.         
  90.         HMShowMenuBalloon(    inItem, theMenu[0]->menuID, theMenu[0]->enableFlags, 0,
  91.                             tip, itemRect, nil, 0, 0);
  92.         }
  93.     else
  94.         HMRemoveBalloon();
  95.     
  96.     return noErr;    
  97. }
  98.  
  99.  
  100.  
  101.  
  102.